package com.daylightrobbery.mapper;

import com.daylightrobbery.entity.UserSignInLog;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
public interface UserSignInLogMapper {

    // 插入日志
    @Insert("INSERT INTO user_signin_logs (uid, type, ctime, ip, province, city, region, addr, device_model, device_name, device_type) " +
            "VALUES (#{log.uid}, #{log.type}, #{log.ctime}, #{log.ip}, #{log.province}, #{log.city}, #{log.region}, #{log.addr}, #{log.deviceModel}, #{log.deviceName}, #{log.deviceType})")
    void insertLog(@Param("log") UserSignInLog log);

    // 根据ID查询日志
    @Select("SELECT * FROM user_signin_logs WHERE log_id = #{logId}")
    UserSignInLog selectLogById(@Param("logId") int logId);

    // 更新日志
    @Update("UPDATE user_signin_logs SET uid = #{log.uid}, type = #{log.type}, ctime = #{log.ctime}, ip = #{log.ip}, province = #{log.province}, city = #{log.city}, region = #{log.region}, addr = #{log.addr}, device_model = #{log.deviceModel}, device_name = #{log.deviceName}, device_type = #{log.deviceType} WHERE log_id = #{log.logId}")
    void updateLog(@Param("log") UserSignInLog log);

    // 删除日志
    @Delete("DELETE FROM user_signin_logs WHERE log_id = #{logId}")
    void deleteLogById(@Param("logId") int logId);

    // 查询所有日志
    @Select("SELECT * FROM user_signin_logs")
    List<UserSignInLog> selectAllLogs();
}
